<?php namespace Admin\Controller;
use Common\Model\User;
use Hdphp\Controller\Controller;

//登陆控制器
class LoginController extends Controller{
	/**
	 * 登陆
	 */
	public function index(){
		if(IS_POST){
			$userModel = new User();
			$username = Q('post.username');
			$password = Q('post.password','','md5');
			$userData = $userModel->where("username='{$username}'")->find();
			if(!$userData){
				View::error('用户名或密码错误');
			}
			if($userData['password'] != $password){
				View::error('用户名或密码错误');
			}
			//$_SESSION['uid']是和rbac中的auth_key配置项是一样的
			$_SESSION['uid'] = $userData['uid'];
			$_SESSION['username'] = $userData['username'];

			View::success('登陆成功',U('Index/index'));
		}
		View::make();
	}

	/**
	 * 退出登陆
	 */
	public function out(){
		session_unset();
		session_destroy();
		View::success('退出成功',U('index'));
	}
}
